package jblip.gui.components;

import java.util.HashMap;
import java.util.Map;

import javax.swing.JScrollPane;
import javax.swing.JSplitPane;

import jblip.gui.components.view.UpdateChannelPanel;
import jblip.gui.data.channels.UpdatesDataChannel;

public class ActionPanel extends JSplitPane {
  private static final long serialVersionUID = 1L;

  private final Map<UpdatesDataChannel, UpdateChannelPanel> channel_panels;

  private final JScrollPane view_panel;

  private final InputPanel input_panel;

  public ActionPanel() {
    super(JSplitPane.VERTICAL_SPLIT);
    view_panel = new JScrollPane();
    input_panel = new InputPanel();
    add(view_panel, JSplitPane.TOP);
    add(input_panel, JSplitPane.BOTTOM);
    setDividerSize(2);
    setResizeWeight(1.0);

    channel_panels = new HashMap<UpdatesDataChannel, UpdateChannelPanel>();
  }

  public void viewChannel(final UpdatesDataChannel channel) {
    UpdateChannelPanel panel = channel_panels.get(channel);
    if (panel == null) {
      panel = new UpdateChannelPanel(channel);
      channel_panels.put(channel, panel);
    }
    view_panel.setViewportView(panel);
    input_panel.setChannel(channel);
  }

}
